package com.ldk.base.framework.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {
	/**
	 * 手机号验证
	 * @param input
	 * @return
	 */
	public static Boolean isPhoneNo(String input){
		Pattern p = Pattern.compile("0?(13|14|15|17|18)[0-9]{9}");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	
	/**
	 * 邮箱验证
	 * @param input
	 * @return
	 */
	public static Boolean isEmail(String input){
		Pattern p = Pattern.compile("\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	/**
	 * 整数验证
	 * @param input
	 * @return
	 */
	public static Boolean isInt(String input){
		Pattern p = Pattern.compile("^-?[0-9]\\d*$");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	/**
	 * 正整数验证
	 * @param input
	 * @return
	 */
	public static Boolean isUInt(String input){
		Pattern p = Pattern.compile("^[0-9]\\d*$");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	/**
	 * 浮点数验证
	 * @param input
	 * @return
	 */
	public static Boolean isNumber(String input){
		Pattern p = Pattern.compile("^(-?\\d+)(\\.\\d+)?$");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	
	/**
	 * 身份证号
	 * @param input
	 * @return
	 */
	public static Boolean isIdCard(String input){
		Pattern p = Pattern.compile("\\d{17}[\\d|x]|\\d{15}");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	
	/**
	 * 中文字符
	 * @param input
	 * @return
	 */
	public static Boolean isZhCn(String input){
		Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	
	/**
	 * Http URL地址
	 * @param input
	 * @return
	 */
	public static Boolean isHttpUrl(String input){
		Pattern p = Pattern.compile("^((https|http|ftp|rtsp|mms)?:\\/\\/)[^\\s]+");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();
	}
	
	/**
	 * IP地址
	 * @param input
	 * @return
	 */
	public static Boolean isIP(String input) {
		Pattern p = Pattern.compile("(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)");
		Matcher matcher = p.matcher(input);
		
		return matcher.matches();       
	}
	/**
	 * 过滤两个以上空白字符
	 * @param input
	 * @return
	 */
	public static String filterSpace(String input){
		Pattern p = Pattern.compile("\\s{2,}");
		Matcher matcher = p.matcher(input);
		return matcher.replaceAll("");
	}
}
